package com.prig.base.util.response;

import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.HashMap;
import java.util.Map;

@ApiModel(value = "基本返回类型",description = "基本返回类型")
public class Result<T> {


    @ApiModelProperty(value = "响应状态码",example = "200")
    private int code = 200;
    @ApiModelProperty(value = "返回信息",example = "成功")
    private String msg ="Success";
    @ApiModelProperty(value = "返回数据",example = "{}")
    private T data;
    @ApiModelProperty(value = "返回数据总数",example = "100")
    private long count = 0;

    @JsonValue
    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("msg", getMsg());
        map.put("code", getCode());
        map.put("data",getData());
        map.put("count",getCount());
        return map;
    }

    public Result c400(String msg){
        return c400(msg,null);
    }
    public Result c400(String msg,T data){
        this.code = 400;
        this.msg = msg;
        this.data = data;
        return this;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public Result setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Result setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public long getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public Result(){
    }

    public Result(String msg){
        this.msg =msg;
    }

    public Result(T data) {
        this.data = data;
    }
    public Result(T data,long count) {
        this.data = data;
        this.count = count;
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
}
